package com.example.demo.leetcode.file;

import java.io.File;
import java.io.PrintWriter;
import java.util.Random;

public class DataProducer {

    /**
     * 创建数据
     * @param count 数据量
     * @param out 输出文件路径
     */
    public static void produce(int count, String out) {
        long t1 = System.currentTimeMillis();
        File file = new File(out);
        if(file.exists())
            file.delete();

        try (PrintWriter writer = new PrintWriter(file, "UTF-8");) {
            Random random = new Random();
            for(int i=0; i<count; i++){
                writer.write(random.nextInt(count) + "\n");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        long t2 = System.currentTimeMillis();
        System.out.println("创建成功！耗时：" + (t2 - t1) + "毫秒。");
    }

}

